package com.mlxg.jxt.web.config;

import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class VerifycationFilter extends GenericFilter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) servletRequest;
        HttpServletResponse resp = (HttpServletResponse) servletResponse;
//        if ("POST".equals(req.getMethod())&&"/doLogin".equals(req.getServletPath())){
//            String code = req.getParameter("code");
//            String verifyCode = (String) req.getSession().getAttribute("verify_code");
//            if (StrUtil.isEmpty(code) || !verifyCode.toLowerCase().equals(code.toLowerCase())){
//                //不正确
//                resp.setContentType("application/json;charset=utf-8");
//                PrintWriter out = resp.getWriter();
//                out.write(new ObjectMapper().writeValueAsString(RespBean.error("验证码填写错误")));
//                out.flush();
//                out.close();
//                return;
//            }
//        }
        filterChain.doFilter(req, resp);
    }
}
